<?php 
/*
   Copyright 2010, Sanket Parab

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   
   This is part of the e-TAT Architecture Package and will be featured in the final e-TAT Application (Phase 1).

   Student class: Holds data on every student present in a group, belonging to a course.
 */
class Student {
	/**
	 * Constructor
	 * @param $id ID of the Student
	 */
	function __construct($id) {
		$query = mysql_query("SELECT * FROM `student` WHERE `id` = '$id';") or die(mysql_error());
		$result = mysql_fetch_object($query);
		if($result) {
			foreach($result as $key=>$value) {
				$this->$key = $value;
			}
		}
	}
	/**
	 * Updates student data
	 */
	public function updateStudent() {
		$query = mysql_query("UPDATE `student` SET `full_name` = '$this->full_name', `email` = '$this->email', `group_id` = '$this->group_id' WHERE `id` = '$this->id'") or die(mysql_error());
		return true;
	}
	/**
	 * Gets count of all forum posts made by this student
	 */
	public function getForumCount(){
		$query = mysql_query("SELECT * FROM `forum` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all SVN commits made by this student
	 */
	public function getSVNCount(){
		$query = mysql_query("SELECT * FROM `svn` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all wiki posts made by this student
	 */
	public function getWikiCount(){
		$query = mysql_query("SELECT * FROM `wiki` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all files added/modified by this student
	 */
	public function getFileCount(){
		$query = mysql_query("SELECT * FROM `file` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Gets count of all issues added/modified made by this student
	 */
	public function getIssueCount(){
		$query = mysql_query("SELECT * FROM `issue` WHERE `author` = '$this->id'") or die(mysql_error());
		$count = mysql_num_rows($query);
		return $count;
	}
	/**
	 * Removes the Student from his/her Group
	 */
	public function remove() {
		$this->group_id = '';
		$this->updateStudent();
	}
}